#pragma once

#include <atlmisc.h>
#include "ListItem.h"
#include "Theme.h"
#include "Common.h"

#define DT_DEFAULT      (DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS)
#define DT_MULTILINE    (DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS | DT_WORDBREAK)

class CBaseListItem : public CListItem
{
public:
  CBaseListItem(const TCHAR* text)
  { if (text) m_text = text; }

  // Drawing
  virtual void Draw(HDC hdc, const RECT& rc) const
  {
    DrawBackground(hdc, rc);
    DrawText(hdc, rc, m_text);
  }

  // Data
  const CString& GetText() const
  { return m_text; }
  void SetText(const CString& text)
  { m_text = text; }

protected:
  void DrawBackground(HDC hdc, const RECT& rc,
                COLORREF bg1 = CTheme::clrListItemSelBg1, COLORREF bg2 = CTheme::clrListItemSelBg2, HBRUSH hbrSep = CTheme::brListItemSeparator) const
  {
    // Draw background
    if (this->GetHovered())
      CTheme::DrawGradientGDI(hdc, rc, bg1, bg2);
    // Draw separator
    RECT rcSep = rc;
    rcSep.top = rcSep.bottom - 1;
    ::FillRect(hdc, &rcSep, hbrSep);
  }

  void DrawText(HDC hdc, const RECT& rc, const CString& text, int flags = DT_DEFAULT,
                CThemeFont& fnt = CTheme::fntListItem, COLORREF clr = CTheme::clrListItemText, COLORREF clrSel = CTheme::clrListItemSelText) const
  {
    ::SelectObject(hdc, fnt.font);
    if (this->GetHovered())
      ::SetTextColor(hdc, clrSel);
    else
      ::SetTextColor(hdc, clr);
    RECT rcText = rc;
    rcText.left += CTheme::iListItemIndent;
    ::DrawText(hdc, text, text.GetLength(), &rcText, flags);
  }

protected:
  CString m_text;
};